Page({
  data: {
    routeList: [
      {from: "深圳", to: "东莞"},
      {from: "广州", to: "深圳"},
      {from: "东莞", to: "珠海"},
      {from: "珠海", to: "深圳"},
      {from: "珠海", to: "广州"},
      {from: "广州", to: "珠海"},
      {from: "深圳", to: "珠海"},
      {from: "深圳", to: "珠海"},
      {from: "深圳", to: "珠海"},
    ],
    origin: '请选择',
    terminus: '请选择',
  },


  origin() {
    wx.navigateTo({
      url: '/pages/site/site?type=origin', // 传递参数 type=origin
    });
  },

  terminus() {
    wx.navigateTo({
      url: '/pages/site/site?type=terminus', // 传递参数 type=terminus
    });
  },

  swap() {
    const { origin, terminus } = this.data;
    if (origin !== '请选择' && terminus !== '请选择') {
      this.setData({
        origin: terminus,
        terminus: origin,
      });
    } else {
      wx.showToast({
        title: '请先选择出发地和目的地',
        icon: 'none',
      });
    }
  },

  query() {
    const { origin, terminus } = this.data;
    wx.navigateTo({
      url: `/pages/date/date?origin=${origin}&terminus=${terminus}`,
    });
  },

  onLoad(options) {
  },

  onShow() {
    const selectedCity = wx.getStorageSync('selectedCity'); // 获取存储的数据
    if (selectedCity) {
      const { toin, type } = selectedCity;
      if (type === 'origin') {
        this.setData({ origin: toin });
      } else if (type === 'terminus') {
        this.setData({ terminus: toin });
      }
      wx.removeStorageSync('selectedCity'); // 清除缓存
    }
  },
});